package com.rritw.webtools.json;

import java.lang.reflect.Field;

public class JSONObject extends org.codehaus.jettison.json.JSONObject {

    private static final long serialVersionUID = 5971532759687392048L;

    public JSONObject(Object object){
        super();
        Class c = object.getClass();
        Field[] fields = c.getDeclaredFields();
        String[] names = new String[fields.length];
        int index = 0;
        for (Field field : fields) {
            field.setAccessible(true);
            names[index] = field.getName();
            index++;
        }
        for (int i = 0; i < names.length; i += 1) {
            try {
                String name = names[i];
                Field field = c.getDeclaredField(name);
                field.setAccessible(true);
                Object value = field.get(object);
                this.put(name, value);
            } catch (Exception e) {
                /* forget about it */
            }
        }
    }

}
